package com.wuyan.locationdog.ui.my

import android.graphics.Typeface
import android.view.inputmethod.EditorInfo
import androidx.fragment.app.Fragment
import com.arcsoft.commonbase.base.BaseBindingActivity
import com.arcsoft.commonbase.ext.hideSoftInput
import com.arcsoft.commonbase.ext.textStringTrim
import com.arcsoft.commonbase.utils.VpAdapter
import com.flyco.tablayout.listener.OnTabSelectListener
import com.wuyan.locationdog.databinding.MyShareManagerActivityBinding


class MyShareManageActivity : BaseBindingActivity<MyShareManagerActivityBinding>() {
    var fragments = mutableListOf<Fragment>()


    override fun initData() {
        setTitleText("")

        val tabTitles = mutableListOf<String>()
        tabTitles.add("共享")
        tabTitles.add("接受")


        binding.apply {

            tabTitles.forEach {
                fragments.add(MyShareListFragment(it))
            }
            viewPager.apply {
                adapter = VpAdapter(supportFragmentManager, fragments)
                offscreenPageLimit = fragments.size
            }

            tabLayout.setViewPager(viewPager, tabTitles.toTypedArray())
            tabLayout.getTitleView(0).apply {
                typeface = Typeface.DEFAULT_BOLD
                textSize = 15F
            }
            tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
                override fun onTabSelect(position: Int) {
                    tabTitles.forEachIndexed { index, s ->
                        tabLayout.getTitleView(index).apply {
                            typeface = Typeface.DEFAULT
                            textSize = 13F
                        }
                    }
                    tabLayout.getTitleView(position).apply {
                        typeface = Typeface.DEFAULT_BOLD
                        textSize = 15F
                    }
                }

                override fun onTabReselect(position: Int) {

                }
            })

            //键盘的搜索按钮
            etSearch.setOnEditorActionListener { _, actionId, _ ->
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    (fragments.get(viewPager.currentItem) as MyShareListFragment).apply {
                        loadNet(etSearch.textStringTrim())
                    }
                    etSearch.hideSoftInput()


                }
                false
            }

        }
    }


}